$(function(){
    makeQrCode();
    $("body").on('click',".copyUrl",function () {
        copyUrl();
    }).on("click","#updateQrCode",function () {
        updateQRCode()
    })
});


function makeQrCode() {
    let id = $("#courseId").val();
    let type = $("#type").val();
    let shareUrl = "http://" + mobilePath + "/mobile/course/" + type + "?courseId=" + id;
    document.createElement('canvas').getContext('2d');
    let h5Code= $('#shareQrCode').qrcode({render: "canvas", height: 200, width: 200, correctLevel: 2, text: shareUrl}).find("canvas").hide();
    let h5CodeUrl=h5Code[0].toDataURL()
    $("#QRCode").attr("src", h5CodeUrl);
    $("#shareUrl").val(shareUrl)
    $(".copyLink").text(shareUrl);
}


/**
 * 下载二维码
 * @param shareUrl
 */
function updateQRCode() {
    let shareUrl = $("#shareUrl").val();
    //window.open(baseloaction+"/admin/microPage/encodeQRCode?text="+shareUrl);
    window.location.href = baseloaction +'/admin/course/cou/encodeQRCode?shareUrl='+shareUrl
}


function copyUrl() {

    var shareUrl = $("#shareUrl");
    shareUrl.select(); // 选择对象
    document.execCommand("Copy"); // 执行浏览器复制命令
    layer.msg("已复制")
}